*****Conscription and Military Service: Do They Result in Future Violent and Non-Violent Incarcerations and Recidivism?  Wang, Flores-Lagunes 2020*****
***This dofile creates Figure 3
clear all

cd "C:\Users\xinto\Dropbox\Vietnam Veteran Paper\Crime Paper\2020 JHR Data\6. Figure 3"
set matsize 1000
set more off 

do CLR_01272015.ado

global outcomes1="currentViolent violent_desistence"
global outcomes2="nonviolent_new nonviolent_desistance"
global outcomes="currentViolent nonviolent_new violent_desistence nonviolent_desistance"

*Extract bounds estimates from the bootstrapped data 
*Violent Crime Outcomes
foreach race in 1 0 {

local i=1	
	
foreach outcome in $outcomes1 {
   
           
use vc_`outcome'_ygroup1_white`race'_I2_be, clear
qui bstat using vc_`outcome'_ygroup1_white`race'_I2_be
set more off

estat bootstrap,per

matrix b = e(b)
mat list b

matrix Vb = e(V)
matrix se = e(se)

sca N=b[1,12]
sca list N
set more off

*P1: LNATE for nt  
matrix lb_LNATE_nt=b[1,40]'
matrix list lb_LNATE_nt
matrix ub_LNATE_nt=b[1,41]'
matrix list ub_LNATE_nt

matrix Vlb_LNATE_nt=Vb[40,40]
matrix list Vlb_LNATE_nt

matrix Vub_LNATE_nt=Vb[41,41]
matrix list Vub_LNATE_nt

set seed 1989

*This part calculate the 95% CI
CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 0.05
mat Lb_LNATE_nt_95=e(Lstar)
mat list Lb_LNATE_nt_95
mat Ub_LNATE_nt_95=e(Ustar)
mat list Ub_LNATE_nt_95
mat CILb_LNATE_nt_95=e(CIL)
mat list CILb_LNATE_nt_95
mat CIUb_LNATE_nt_95=e(CIU)
mat list CIUb_LNATE_nt_95

*This part calculate the 90% CI
CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 0.1
mat Lb_LNATE_nt_90=e(Lstar)
mat list Lb_LNATE_nt_90
mat Ub_LNATE_nt_90=e(Ustar)
mat list Ub_LNATE_nt_90
mat CILb_LNATE_nt_90=e(CIL)
mat list CILb_LNATE_nt_90
mat CIUb_LNATE_nt_90=e(CIU)
mat list CIUb_LNATE_nt_90

*This part compute the p-value of the CI excluding zero

qui CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 0.3
mat Lb_LNATE_nt_300=e(Lstar)
mat list Lb_LNATE_nt_300
mat CILb_LNATE_nt_300=e(CIL)
mat list CILb_LNATE_nt_300
mat Ub_LNATE_nt_300=e(Ustar)
mat list Ub_LNATE_nt_300
mat CIUb_LNATE_nt_300=e(CIU)
mat list CIUb_LNATE_nt_300

local alpha=0.3
local alpha1000=`alpha'*1000 

local Lb_LNATE_nt_`alpha1000'=Lb_LNATE_nt_`alpha1000'[1,1]
local CILb_LNATE_nt_`alpha1000'=CILb_LNATE_nt_`alpha1000'[1,1]
local Ub_LNATE_nt_`alpha1000'=Ub_LNATE_nt_`alpha1000'[1,1]
local CIUb_LNATE_nt_`alpha1000'=CIUb_LNATE_nt_`alpha1000'[1,1]

*set pvalue=1
local pvalue=1

if `Lb_LNATE_nt_`alpha1000''>0 {

while `CILb_LNATE_nt_`alpha1000''>0 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'/2"
qui CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 `alpha'
mat Lb_LNATE_nt_`alpha1000'=e(Lstar)
mat list Lb_LNATE_nt_`alpha1000'
mat CILb_LNATE_nt_`alpha1000'=e(CIL)
mat list CILb_LNATE_nt_`alpha1000'
local CILb_LNATE_nt_`alpha1000'=CILb_LNATE_nt_`alpha1000'[1,1]
      }
local pvalue=(`alpha'+0.001)	  
display "the CI of the lower bound excludes zero at the level of `pvalue'" 
   } 
else {
if `Ub_LNATE_nt_`alpha1000''<0 {

while `CIUb_LNATE_nt_`alpha1000''<0 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'/2"
qui CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 `alpha'
mat Ub_LNATE_nt_`alpha1000'=e(Ustar)
mat list Ub_LNATE_nt_`alpha1000'
mat CIUb_LNATE_nt_`alpha1000'=e(CIU)
mat list CIUb_LNATE_nt_`alpha1000'
local CIUb_LNATE_nt_`alpha1000'=CIUb_LNATE_nt_`alpha1000'[1,1]
      }
local pvalue=(`alpha'+0.001)	  
display "the CI of the upper bound excludes zero at the level of `pvalue'" 
   } 
}

*Generate variables needed for the figure 
*X-axis
gen GROUP=`i'
*Scatter points
gen AVG=b[1,20]
gen EY_00=b[1,23]
gen LATE_perc=Lb_LNATE_nt_95[1,1]/EY_00
gen L_Lnt=Lb_LNATE_nt_95[1,1]
gen U_Lnt=Ub_LNATE_nt_95[1,1]
gen CI_L_Lnt_95=CILb_LNATE_nt_95[1,1]
gen CI_U_Lnt_95=CIUb_LNATE_nt_95[1,1]
gen CI_L_Lnt_90=CILb_LNATE_nt_90[1,1]
gen CI_U_Lnt_90=CIUb_LNATE_nt_90[1,1]
gen pvalue=`pvalue'

keep GROUP AVG EY_00 LATE_perc L_Lnt U_Lnt CI_L_Lnt_95 CI_U_Lnt_95 CI_L_Lnt_90 CI_U_Lnt_90 pvalue

save Figure_`outcome'_`race', replace

local i=`i'+2
                                   }
				}  


**Nonviolent outcomes 
local i=2
foreach outcome in $outcomes2 {
  /* The white results   */  
use vc_`outcome'_ygroup1_white_nonwhite_test_I2_be, clear
qui bstat using vc_`outcome'_ygroup1_white_nonwhite_test_I2_be
set more off

estat bootstrap,per

matrix b = e(b)
mat list b

matrix Vb = e(V)
matrix se = e(se)

sca N=b[1,1]
sca list N
set more off

*P1: LNATE for nt  
matrix lb_LNATE_nt=b[1,24]'
matrix list lb_LNATE_nt
matrix ub_LNATE_nt=b[1,25]'
matrix list ub_LNATE_nt

matrix Vlb_LNATE_nt=Vb[24,24]
matrix list Vlb_LNATE_nt

matrix Vub_LNATE_nt=Vb[25,25]
matrix list Vub_LNATE_nt

set seed 1989

CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 0.05
mat Lb_LNATE_nt_95=e(Lstar)
mat list Lb_LNATE_nt_95
mat Ub_LNATE_nt_95=e(Ustar)
mat list Ub_LNATE_nt_95
mat CILb_LNATE_nt_95=e(CIL)
mat list CILb_LNATE_nt_95
mat CIUb_LNATE_nt_95=e(CIU)
mat list CIUb_LNATE_nt_95

CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 0.1
mat Lb_LNATE_nt_90=e(Lstar)
mat list Lb_LNATE_nt_90
mat Ub_LNATE_nt_90=e(Ustar)
mat list Ub_LNATE_nt_90
mat CILb_LNATE_nt_90=e(CIL)
mat list CILb_LNATE_nt_90
mat CIUb_LNATE_nt_90=e(CIU)
mat list CIUb_LNATE_nt_90

*This part compute the p-value of the CI excluding zero

qui CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 0.3
mat Lb_LNATE_nt_300=e(Lstar)
mat list Lb_LNATE_nt_300
mat CILb_LNATE_nt_300=e(CIL)
mat list CILb_LNATE_nt_300
mat Ub_LNATE_nt_300=e(Ustar)
mat list Ub_LNATE_nt_300
mat CIUb_LNATE_nt_300=e(CIU)
mat list CIUb_LNATE_nt_300

local alpha=0.3
local alpha1000=`alpha'*1000 

local Lb_LNATE_nt_`alpha1000'=Lb_LNATE_nt_`alpha1000'[1,1]
local CILb_LNATE_nt_`alpha1000'=CILb_LNATE_nt_`alpha1000'[1,1]
local Ub_LNATE_nt_`alpha1000'=Ub_LNATE_nt_`alpha1000'[1,1]
local CIUb_LNATE_nt_`alpha1000'=CIUb_LNATE_nt_`alpha1000'[1,1]

*set pvalue=1
local pvalue=1

if `Lb_LNATE_nt_`alpha1000''>0 {

while `CILb_LNATE_nt_`alpha1000''>0 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'/2"
qui CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 `alpha'
mat Lb_LNATE_nt_`alpha1000'=e(Lstar)
mat list Lb_LNATE_nt_`alpha1000'
mat CILb_LNATE_nt_`alpha1000'=e(CIL)
mat list CILb_LNATE_nt_`alpha1000'
local CILb_LNATE_nt_`alpha1000'=CILb_LNATE_nt_`alpha1000'[1,1]
      }
local pvalue=(`alpha'+0.001)	  
display "the CI of the lower bound excludes zero at the level of `pvalue'" 
   } 
else {
if `Ub_LNATE_nt_`alpha1000''<0 {

while `CIUb_LNATE_nt_`alpha1000''<0 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'/2"
qui CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 `alpha'
mat Ub_LNATE_nt_`alpha1000'=e(Ustar)
mat list Ub_LNATE_nt_`alpha1000'
mat CIUb_LNATE_nt_`alpha1000'=e(CIU)
mat list CIUb_LNATE_nt_`alpha1000'
local CIUb_LNATE_nt_`alpha1000'=CIUb_LNATE_nt_`alpha1000'[1,1]
      }
local pvalue=(`alpha'+0.001)	  
display "the CI of the upper bound excludes zero at the level of `pvalue'" 
   } 
}


*Generate variables needed for the figure 
*X-axis
gen GROUP=`i'
*Scatter points
gen AVG=b[1,4]
gen EY_00=b[1,7]
gen LATE_perc=Lb_LNATE_nt_95[1,1]/EY_00
gen L_Lnt=Lb_LNATE_nt_95[1,1]
gen U_Lnt=Ub_LNATE_nt_95[1,1]
gen CI_L_Lnt_95=CILb_LNATE_nt_95[1,1]
gen CI_U_Lnt_95=CIUb_LNATE_nt_95[1,1]
gen CI_L_Lnt_90=CILb_LNATE_nt_90[1,1]
gen CI_U_Lnt_90=CIUb_LNATE_nt_90[1,1]
gen pvalue=`pvalue'


keep GROUP AVG EY_00 LATE_perc L_Lnt U_Lnt CI_L_Lnt_95 CI_U_Lnt_95 CI_L_Lnt_90 CI_U_Lnt_90 pvalue

save Figure_`outcome'_1, replace
 
 /* The nonwhite results   */  
use vc_`outcome'_ygroup1_white_nonwhite_test_I2_be, clear
qui bstat using vc_`outcome'_ygroup1_white_nonwhite_test_I2_be
set more off

estat bootstrap,per

matrix b = e(b)
mat list b

matrix Vb = e(V)
matrix se = e(se)

sca N=b[1,465]
sca list N
set more off

*P1: LNATE for nt  
matrix lb_LNATE_nt=b[1,488]'
matrix list lb_LNATE_nt
matrix ub_LNATE_nt=b[1,489]'
matrix list ub_LNATE_nt

matrix Vlb_LNATE_nt=Vb[488,488]
matrix list Vlb_LNATE_nt

matrix Vub_LNATE_nt=Vb[489,489]
matrix list Vub_LNATE_nt

set seed 1989

CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 0.05
mat Lb_LNATE_nt_95=e(Lstar)
mat list Lb_LNATE_nt_95
mat Ub_LNATE_nt_95=e(Ustar)
mat list Ub_LNATE_nt_95
mat CILb_LNATE_nt_95=e(CIL)
mat list CILb_LNATE_nt_95
mat CIUb_LNATE_nt_95=e(CIU)
mat list CIUb_LNATE_nt_95

CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 0.1
mat Lb_LNATE_nt_90=e(Lstar)
mat list Lb_LNATE_nt_90
mat Ub_LNATE_nt_90=e(Ustar)
mat list Ub_LNATE_nt_90
mat CILb_LNATE_nt_90=e(CIL)
mat list CILb_LNATE_nt_90
mat CIUb_LNATE_nt_90=e(CIU)
mat list CIUb_LNATE_nt_90

*This part compute the p-value of the CI excluding zero

qui CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 0.3
mat Lb_LNATE_nt_300=e(Lstar)
mat list Lb_LNATE_nt_300
mat CILb_LNATE_nt_300=e(CIL)
mat list CILb_LNATE_nt_300
mat Ub_LNATE_nt_300=e(Ustar)
mat list Ub_LNATE_nt_300
mat CIUb_LNATE_nt_300=e(CIU)
mat list CIUb_LNATE_nt_300

local alpha=0.3
local alpha1000=`alpha'*1000 

local Lb_LNATE_nt_`alpha1000'=Lb_LNATE_nt_`alpha1000'[1,1]
local CILb_LNATE_nt_`alpha1000'=CILb_LNATE_nt_`alpha1000'[1,1]
local Ub_LNATE_nt_`alpha1000'=Ub_LNATE_nt_`alpha1000'[1,1]
local CIUb_LNATE_nt_`alpha1000'=CIUb_LNATE_nt_`alpha1000'[1,1]

*set pvalue=1
local pvalue=1

if `Lb_LNATE_nt_`alpha1000''>0 {

while `CILb_LNATE_nt_`alpha1000''>0 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'/2"
qui CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 `alpha'
mat Lb_LNATE_nt_`alpha1000'=e(Lstar)
mat list Lb_LNATE_nt_`alpha1000'
mat CILb_LNATE_nt_`alpha1000'=e(CIL)
mat list CILb_LNATE_nt_`alpha1000'
local CILb_LNATE_nt_`alpha1000'=CILb_LNATE_nt_`alpha1000'[1,1]
      }
local pvalue=(`alpha'+0.001)	  
display "the CI of the lower bound excludes zero at the level of `pvalue'" 
   } 
else {
if `Ub_LNATE_nt_`alpha1000''<0 {

while `CIUb_LNATE_nt_`alpha1000''<0 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'/2"
qui CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 `alpha'
mat Ub_LNATE_nt_`alpha1000'=e(Ustar)
mat list Ub_LNATE_nt_`alpha1000'
mat CIUb_LNATE_nt_`alpha1000'=e(CIU)
mat list CIUb_LNATE_nt_`alpha1000'
local CIUb_LNATE_nt_`alpha1000'=CIUb_LNATE_nt_`alpha1000'[1,1]
      }
local pvalue=(`alpha'+0.001)	  
display "the CI of the upper bound excludes zero at the level of `pvalue'" 
   } 
}


*Generate variables needed for the figure 
*X-axis
gen GROUP=`i'
*Scatter points
gen AVG=b[1,468]
gen EY_00=b[1,471]
gen LATE_perc=Lb_LNATE_nt_95[1,1]/EY_00
gen L_Lnt=Lb_LNATE_nt_95[1,1]
gen U_Lnt=Ub_LNATE_nt_95[1,1]
gen CI_L_Lnt_95=CILb_LNATE_nt_95[1,1]
gen CI_U_Lnt_95=CIUb_LNATE_nt_95[1,1]
gen CI_L_Lnt_90=CILb_LNATE_nt_90[1,1]
gen CI_U_Lnt_90=CIUb_LNATE_nt_90[1,1]
gen pvalue=`pvalue'

keep GROUP AVG EY_00 LATE_perc L_Lnt U_Lnt CI_L_Lnt_95 CI_U_Lnt_95 CI_L_Lnt_90 CI_U_Lnt_90 pvalue

save Figure_`outcome'_0, replace
 
local i=`i'+2
 }
				

				
*Panel A: white 1948-1952				 				
use Figure_currentViolent_1, clear 
append using Figure_nonviolent_new_1
append using Figure_violent_desistence_1 
append using Figure_nonviolent_desistance_1 

collapse (mean) AVG EY_00 LATE_perc L_Lnt U_Lnt CI_L_Lnt_95 CI_U_Lnt_95 CI_L_Lnt_90 CI_U_Lnt_90 pvalue, by(GROUP)
label define groupname 1 "Violent Crime" 2 "Nonviolent Crime" 3 "Violent Recidivism" 4 "Nonviolent Recidivism"
label values GROUP groupname 

gen PP_AVG=AVG*100 
gen PP_EY_00=EY_00*100
gen PP_LATE_perc=LATE_perc*100 
gen PP_L_Lnt=L_Lnt*100
gen PP_U_Lnt=U_Lnt*100
gen PP_CI_L_Lnt_95=CI_L_Lnt_95*100
gen PP_CI_U_Lnt_95=CI_U_Lnt_95*100 
gen PP_CI_L_Lnt_90=CI_L_Lnt_90*100 
gen PP_CI_U_Lnt_90=CI_U_Lnt_90*100

twoway (rbar PP_U_Lnt PP_L_Lnt GROUP, barwidth(0.5) color(gray) yline(0, lcolor(black)) xlab(1(1)4, valuelabel labsize(small))), ylabel( -0.1(0.1)0.3, labsize(small) grid glcolor(black) glpattern(dot)) /// 
legend (order(1 "The Effect Upper and Lower Bounds" 2 "90% CI" 3 "95% CI" 4 "E[Y|D=0, Z=0]" ))  ///   
title("Panel (A) White Draft Avoiders Born in 1948-1952") ///
xtitle("") ///
graphregion(color(white)) ///
|| (rcap PP_CI_U_Lnt_95 PP_CI_L_Lnt_95 GROUP, msize(vhuge) lw(vvthin) msize(vlarge) lwidth(median) color(black)) ///
|| (rcap PP_CI_U_Lnt_90 PP_CI_L_Lnt_90 GROUP, msize(vhuge) lw(vvthin) msize(vlarge) lwidth(median) color(black)) ///
|| (scatter PP_EY_00 GROUP, msymbol(*) color(black) msize(vvlarge) mlw(thick))

graph save Figure_3_1, replace 

			
*Panel B: nonwhite 1948-1952						
use Figure_currentViolent_0, clear 
append using Figure_nonviolent_new_0
append using Figure_violent_desistence_0 
append using Figure_nonviolent_desistance_0 

collapse (mean) AVG EY_00 LATE_perc L_Lnt U_Lnt CI_L_Lnt_95 CI_U_Lnt_95 CI_L_Lnt_90 CI_U_Lnt_90 pvalue, by(GROUP)
label define groupname 1 "Violent Crime" 2 "Nonviolent Crime" 3 "Violent Recidivism" 4 "Nonviolent Recidivism"
label values GROUP groupname 

gen PP_AVG=AVG*100 
gen PP_EY_00=EY_00*100
gen PP_LATE_perc=LATE_perc*100 
gen PP_L_Lnt=L_Lnt*100
gen PP_U_Lnt=U_Lnt*100
gen PP_CI_L_Lnt_95=CI_L_Lnt_95*100
gen PP_CI_U_Lnt_95=CI_U_Lnt_95*100 
gen PP_CI_L_Lnt_90=CI_L_Lnt_90*100 
gen PP_CI_U_Lnt_90=CI_U_Lnt_90*100

twoway (rbar PP_U_Lnt PP_L_Lnt GROUP, barwidth(0.5) color(gray) yline(0, lcolor(black)) xlab(1(1)4, valuelabel labsize(small))), ylabel( -1(1)2, labsize(small) grid glcolor(black) glpattern(dot)) /// 
legend (order(1 "The Effect Upper and Lower Bounds" 2 "90% CI" 3 "95% CI" 4 "E[Y|D=0, Z=0]" ))  ///   
title("Panel (B) Nonwhite Draft Avoiders Born in 1948-1952") ///
xtitle("") ///
graphregion(color(white)) ///
|| (rcap PP_CI_U_Lnt_95 PP_CI_L_Lnt_95 GROUP, msize(vhuge) lw(vvthin) msize(vlarge) lwidth(median) color(black)) ///
|| (rcap PP_CI_U_Lnt_90 PP_CI_L_Lnt_90 GROUP, msize(vhuge) lw(vvthin) msize(vlarge) lwidth(median) color(black)) ///
|| (scatter PP_EY_00 GROUP, msymbol(*) color(black) msize(vvlarge) mlw(thick))

graph save Figure_3_2, replace 


******Panel C and D for 1950 only*******
local i=1
foreach outcome in $outcomes {
  /* The white results */  
use vc_`outcome'_ygroup3_white_nonwhite_test_I2_be, clear
qui bstat using vc_`outcome'_ygroup3_white_nonwhite_test_I2_be
set more off

estat bootstrap,per

matrix b = e(b)
mat list b

matrix Vb = e(V)
matrix se = e(se)

sca N=b[1,1]
sca list N
set more off

*P1: LNATE for nt  
matrix lb_LNATE_nt=b[1,24]'
matrix list lb_LNATE_nt
matrix ub_LNATE_nt=b[1,25]'
matrix list ub_LNATE_nt

matrix Vlb_LNATE_nt=Vb[24,24]
matrix list Vlb_LNATE_nt

matrix Vub_LNATE_nt=Vb[25,25]
matrix list Vub_LNATE_nt

set seed 1989

*This part compute the p-value of the CI excluding zero

qui CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 0.3
mat Lb_LNATE_nt_300=e(Lstar)
mat list Lb_LNATE_nt_300
mat CILb_LNATE_nt_300=e(CIL)
mat list CILb_LNATE_nt_300
mat Ub_LNATE_nt_300=e(Ustar)
mat list Ub_LNATE_nt_300
mat CIUb_LNATE_nt_300=e(CIU)
mat list CIUb_LNATE_nt_300

local alpha=0.3
local alpha1000=`alpha'*1000 

local Lb_LNATE_nt_`alpha1000'=Lb_LNATE_nt_`alpha1000'[1,1]
local CILb_LNATE_nt_`alpha1000'=CILb_LNATE_nt_`alpha1000'[1,1]
local Ub_LNATE_nt_`alpha1000'=Ub_LNATE_nt_`alpha1000'[1,1]
local CIUb_LNATE_nt_`alpha1000'=CIUb_LNATE_nt_`alpha1000'[1,1]

*set pvalue=1
local pvalue=1

if `Lb_LNATE_nt_`alpha1000''>0 {

while `CILb_LNATE_nt_`alpha1000''>0 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'/2"
qui CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 `alpha'
mat Lb_LNATE_nt_`alpha1000'=e(Lstar)
mat list Lb_LNATE_nt_`alpha1000'
mat CILb_LNATE_nt_`alpha1000'=e(CIL)
mat list CILb_LNATE_nt_`alpha1000'
local CILb_LNATE_nt_`alpha1000'=CILb_LNATE_nt_`alpha1000'[1,1]
      }
local pvalue=(`alpha'+0.001)	  
display "the CI of the lower bound excludes zero at the level of `pvalue'" 
   } 
else {
if `Ub_LNATE_nt_`alpha1000''<0 {

while `CIUb_LNATE_nt_`alpha1000''<0 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'/2"
qui CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 `alpha'
mat Ub_LNATE_nt_`alpha1000'=e(Ustar)
mat list Ub_LNATE_nt_`alpha1000'
mat CIUb_LNATE_nt_`alpha1000'=e(CIU)
mat list CIUb_LNATE_nt_`alpha1000'
local CIUb_LNATE_nt_`alpha1000'=CIUb_LNATE_nt_`alpha1000'[1,1]
      }
local pvalue=(`alpha'+0.001)	  
display "the CI of the upper bound excludes zero at the level of `pvalue'" 
   } 
}


CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 0.05
mat Lb_LNATE_nt_95=e(Lstar)
mat list Lb_LNATE_nt_95
mat Ub_LNATE_nt_95=e(Ustar)
mat list Ub_LNATE_nt_95
mat CILb_LNATE_nt_95=e(CIL)
mat list CILb_LNATE_nt_95
mat CIUb_LNATE_nt_95=e(CIU)
mat list CIUb_LNATE_nt_95

CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 0.1
mat Lb_LNATE_nt_90=e(Lstar)
mat list Lb_LNATE_nt_90
mat Ub_LNATE_nt_90=e(Ustar)
mat list Ub_LNATE_nt_90
mat CILb_LNATE_nt_90=e(CIL)
mat list CILb_LNATE_nt_90
mat CIUb_LNATE_nt_90=e(CIU)
mat list CIUb_LNATE_nt_90


*Generate variables needed for the figure 
*X-axis
gen GROUP=`i'
*Scatter points
gen AVG=b[1,4]
gen EY_00=b[1,7]
gen LATE_perc=Lb_LNATE_nt_95[1,1]/EY_00
gen L_Lnt=Lb_LNATE_nt_95[1,1]
gen U_Lnt=Ub_LNATE_nt_95[1,1]
gen CI_L_Lnt_95=CILb_LNATE_nt_95[1,1]
gen CI_U_Lnt_95=CIUb_LNATE_nt_95[1,1]
gen CI_L_Lnt_90=CILb_LNATE_nt_90[1,1]
gen CI_U_Lnt_90=CIUb_LNATE_nt_90[1,1]
gen pvalue=`pvalue'

keep GROUP AVG EY_00 LATE_perc L_Lnt U_Lnt CI_L_Lnt_95 CI_U_Lnt_95 CI_L_Lnt_90 CI_U_Lnt_90 pvalue

save Figure_`outcome'_1_1950, replace
 
 /* The nonwhite results */ 
use vc_`outcome'_ygroup3_white_nonwhite_test_I2_be, clear
qui bstat using vc_`outcome'_ygroup3_white_nonwhite_test_I2_be
set more off

estat bootstrap,per

matrix b = e(b)
mat list b

matrix Vb = e(V)
matrix se = e(se)

sca N=b[1,465]
sca list N
set more off

*P1: LNATE for nt  
matrix lb_LNATE_nt=b[1,488]'
matrix list lb_LNATE_nt
matrix ub_LNATE_nt=b[1,489]'
matrix list ub_LNATE_nt

matrix Vlb_LNATE_nt=Vb[488,488]
matrix list Vlb_LNATE_nt

matrix Vub_LNATE_nt=Vb[489,489]
matrix list Vub_LNATE_nt

set seed 1989

*This part compute the p-value of the CI excluding zero

qui CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 0.3
mat Lb_LNATE_nt_300=e(Lstar)
mat list Lb_LNATE_nt_300
mat CILb_LNATE_nt_300=e(CIL)
mat list CILb_LNATE_nt_300
mat Ub_LNATE_nt_300=e(Ustar)
mat list Ub_LNATE_nt_300
mat CIUb_LNATE_nt_300=e(CIU)
mat list CIUb_LNATE_nt_300

local alpha=0.3
local alpha1000=`alpha'*1000 

local Lb_LNATE_nt_`alpha1000'=Lb_LNATE_nt_`alpha1000'[1,1]
local CILb_LNATE_nt_`alpha1000'=CILb_LNATE_nt_`alpha1000'[1,1]
local Ub_LNATE_nt_`alpha1000'=Ub_LNATE_nt_`alpha1000'[1,1]
local CIUb_LNATE_nt_`alpha1000'=CIUb_LNATE_nt_`alpha1000'[1,1]

*set pvalue=1
local pvalue=1

if `Lb_LNATE_nt_`alpha1000''>0 {
while `CILb_LNATE_nt_`alpha1000''>0 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'/2"
qui CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 `alpha'
mat Lb_LNATE_nt_`alpha1000'=e(Lstar)
mat list Lb_LNATE_nt_`alpha1000'
mat CILb_LNATE_nt_`alpha1000'=e(CIL)
mat list CILb_LNATE_nt_`alpha1000'
local CILb_LNATE_nt_`alpha1000'=CILb_LNATE_nt_`alpha1000'[1,1]
      }
local pvalue=(`alpha'+0.001)	  
display "the CI of the lower bound excludes zero at the level of `pvalue'" 
   } 
else {
if `Ub_LNATE_nt_`alpha1000''<0 {

while `CIUb_LNATE_nt_`alpha1000''<0 {
local alpha=`alpha'-0.001
local alpha1000=`alpha'*1000
di "Testing at level of `alpha'/2"
qui CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 `alpha'
mat Ub_LNATE_nt_`alpha1000'=e(Ustar)
mat list Ub_LNATE_nt_`alpha1000'
mat CIUb_LNATE_nt_`alpha1000'=e(CIU)
mat list CIUb_LNATE_nt_`alpha1000'
local CIUb_LNATE_nt_`alpha1000'=CIUb_LNATE_nt_`alpha1000'[1,1]
      }
local pvalue=(`alpha'+0.001)	  
display "the CI of the upper bound excludes zero at the level of `pvalue'" 
   } 
}


CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 0.05
mat Lb_LNATE_nt_95=e(Lstar)
mat list Lb_LNATE_nt_95
mat Ub_LNATE_nt_95=e(Ustar)
mat list Ub_LNATE_nt_95
mat CILb_LNATE_nt_95=e(CIL)
mat list CILb_LNATE_nt_95
mat CIUb_LNATE_nt_95=e(CIU)
mat list CIUb_LNATE_nt_95

CLR lb_LNATE_nt Vlb_LNATE_nt ub_LNATE_nt Vub_LNATE_nt N 100000 0.1
mat Lb_LNATE_nt_90=e(Lstar)
mat list Lb_LNATE_nt_90
mat Ub_LNATE_nt_90=e(Ustar)
mat list Ub_LNATE_nt_90
mat CILb_LNATE_nt_90=e(CIL)
mat list CILb_LNATE_nt_90
mat CIUb_LNATE_nt_90=e(CIU)
mat list CIUb_LNATE_nt_90

*Generate variables needed for the figure 
*X-axis
gen GROUP=`i'
*Scatter points
gen AVG=b[1,468]
gen EY_00=b[1,471]
gen LATE_perc=Lb_LNATE_nt_95[1,1]/EY_00
gen L_Lnt=Lb_LNATE_nt_95[1,1]
gen U_Lnt=Ub_LNATE_nt_95[1,1]
gen CI_L_Lnt_95=CILb_LNATE_nt_95[1,1]
gen CI_U_Lnt_95=CIUb_LNATE_nt_95[1,1]
gen CI_L_Lnt_90=CILb_LNATE_nt_90[1,1]
gen CI_U_Lnt_90=CIUb_LNATE_nt_90[1,1]
gen pvalue=`pvalue'

keep GROUP AVG EY_00 LATE_perc L_Lnt U_Lnt CI_L_Lnt_95 CI_U_Lnt_95 CI_L_Lnt_90 CI_U_Lnt_90 pvalue

save Figure_`outcome'_0_1950, replace
 
local i= `i'+1

 }
				
 		
*Panel C: White born in 1950				
use Figure_currentViolent_1_1950, clear 
append using Figure_nonviolent_new_1_1950
append using Figure_violent_desistence_1_1950 
append using Figure_nonviolent_desistance_1_1950 

collapse (mean) AVG EY_00 LATE_perc L_Lnt U_Lnt CI_L_Lnt_95 CI_U_Lnt_95 CI_L_Lnt_90 CI_U_Lnt_90 pvalue, by(GROUP)
label define groupname 1 "Violent Crime" 2 "Nonviolent Crime" 3 "Violent Recidivism" 4 "Nonviolent Recidivism"
label values GROUP groupname 

gen PP_AVG=AVG*100 
gen PP_EY_00=EY_00*100
gen PP_LATE_perc=LATE_perc*100 
gen PP_L_Lnt=L_Lnt*100
gen PP_U_Lnt=U_Lnt*100
gen PP_CI_L_Lnt_95=CI_L_Lnt_95*100
gen PP_CI_U_Lnt_95=CI_U_Lnt_95*100 
gen PP_CI_L_Lnt_90=CI_L_Lnt_90*100 
gen PP_CI_U_Lnt_90=CI_U_Lnt_90*100


twoway (rbar PP_U_Lnt PP_L_Lnt GROUP, barwidth(0.5) color(gray) yline(0, lcolor(black)) xlab(1(1)4, valuelabel labsize(small))), ylabel( -0.1(0.1)0.3, labsize(small) grid glcolor(black) glpattern(dot)) /// 
legend (order(1 "The Effect Upper and Lower Bounds" 2 "90% CI" 3 "95% CI" 4 "E[Y|D=0, Z=0]" ))  ///   
title("Panel (C) White Draft Avoiders Born in 1950") ///
xtitle("") ///
graphregion(color(white)) ///
|| (rcap PP_CI_U_Lnt_95 PP_CI_L_Lnt_95 GROUP, msize(vhuge) lw(vvthin) msize(vlarge) lwidth(median) color(black)) ///
|| (rcap PP_CI_U_Lnt_90 PP_CI_L_Lnt_90 GROUP, msize(vhuge) lw(vvthin) msize(vlarge) lwidth(median) color(black)) ///
|| (scatter PP_EY_00 GROUP, msymbol(*) color(black) msize(vvlarge) mlw(thick))

graph save Figure_3_3, replace 

			
*Panel D: Nonwhite born in 1950	 				
use Figure_currentViolent_0_1950, clear 
append using Figure_nonviolent_new_0_1950
append using Figure_violent_desistence_0_1950 
append using Figure_nonviolent_desistance_0_1950 

collapse (mean) AVG EY_00 LATE_perc L_Lnt U_Lnt CI_L_Lnt_95 CI_U_Lnt_95 CI_L_Lnt_90 CI_U_Lnt_90 pvalue, by(GROUP)
label define groupname 1 "Violent Crime" 2 "Nonviolent Crime" 3 "Violent Recidivism" 4 "Nonviolent Recidivism"
label values GROUP groupname 

gen PP_AVG=AVG*100 
gen PP_EY_00=EY_00*100
gen PP_LATE_perc=LATE_perc*100 
gen PP_L_Lnt=L_Lnt*100
gen PP_U_Lnt=U_Lnt*100
gen PP_CI_L_Lnt_95=CI_L_Lnt_95*100
gen PP_CI_U_Lnt_95=CI_U_Lnt_95*100 
gen PP_CI_L_Lnt_90=CI_L_Lnt_90*100 
gen PP_CI_U_Lnt_90=CI_U_Lnt_90*100

twoway (rbar PP_U_Lnt PP_L_Lnt GROUP, barwidth(0.5) color(gray) yline(0, lcolor(black)) xlab(1(1)4, valuelabel labsize(small))), ylabel( -1(1)2, labsize(small) grid glcolor(black) glpattern(dot)) /// 
legend (order(1 "The Effect Upper and Lower Bounds" 2 "90% CI" 3 "95% CI" 4 "E[Y|D=0, Z=0]" ))  ///   
title("Panel (D) Nonwhite Draft Avoiders Born in 1950") ///
xtitle("") ///
graphregion(color(white)) ///
|| (rcap PP_CI_U_Lnt_95 PP_CI_L_Lnt_95 GROUP, msize(vhuge) lw(vvthin) msize(vlarge) lwidth(median) color(black)) ///
|| (rcap PP_CI_U_Lnt_90 PP_CI_L_Lnt_90 GROUP, msize(vhuge) lw(vvthin) msize(vlarge) lwidth(median) color(black)) ///
|| (scatter PP_EY_00 GROUP, msymbol(*) color(black) msize(vvlarge) mlw(thick))

graph save Figure_3_4, replace 

graph combine Figure_3_1.gph Figure_3_2.gph Figure_3_3.gph Figure_3_4.gph, rows(2) cols(2) iscale(0.6) ysize(11) xsize(20)
 
